package org.jeecg.chase.modules.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.chase.modules.entity.AdhShopCategory;

import java.util.List;
import java.util.Map;

/**
 * @author leikai
 * @version 1.0
 * @description: 商铺分类
 * @date 2022/01/08/0008 15:20
 */
public interface AdhShopCategoryMapper extends BaseMapper<AdhShopCategory> {

    @Delete("delete from adh_shop_category where id=#{id}")
    void deleteById(@Param("id") String id);

    @Delete("delete from adh_shop_category where parent_id=#{parentId}")
    void deleteByParentId(@Param("parentId") String parentId);

    @Update("update adh_shop_category set category_status=#{status} where id=#{id}")
    void updateStatus(@Param("id") String id, @Param("status") Integer status);

    @Select("select id as value, category_name as text from adh_shop_category where category_status='1' and category_level=1 order by category_order ASC")
    List<Map<String, Object>> queryParentData();

    @Select("select id as value, category_name as text from adh_shop_category where category_status='1' and category_level=2  and parent_id=#{categoryId} order by category_order ASC")
    List<Map<String, Object>> querySubCategoryData(@Param("categoryId") String categoryId);

    @Select(" SELECT * FROM `adh_shop_category`  WHERE category_status='1' AND category_level='1' ORDER BY category_order ASC")
    List<AdhShopCategory> queryCategoryForWeChatIndex();

    @Select(" SELECT * FROM `adh_shop_category`  WHERE category_status='1' AND category_level='2' and parent_id=#{categoryId} ORDER BY category_order ASC")
    List<AdhShopCategory> querySubCategory(@Param("categoryId") String categoryId);

    @Select(" SELECT  adh_coupon_info.* FROM adh_merch_info LEFT JOIN adh_coupon_info  ON adh_merch_info.id = adh_coupon_info.merch_id\n" +
            " LEFT JOIN adh_shop_category ON adh_shop_category.id = adh_merch_info.merch_category\n" +
            " WHERE adh_merch_info.merch_status='1' AND adh_merch_info.merch_index_flag='1' AND adh_coupon_info.if_top=1 AND adh_coupon_info.coupon_status=2\n" +
            " AND (adh_shop_category.id = #{categoryId}  OR adh_shop_category.parent_id = #{categoryId} )")
    List<Map<String,Object>> queryMerchCoupponByCategory(@Param("categoryId") String categoryId);

    @Select(" SELECT  adh_coupon_info.* FROM adh_merch_info LEFT JOIN adh_coupon_info  ON adh_merch_info.id = adh_coupon_info.merch_id\n" +
            " LEFT JOIN adh_shop_category ON adh_shop_category.id = adh_merch_info.merch_category\n" +
            " WHERE adh_merch_info.merch_status='1'  AND adh_coupon_info.if_top=1 AND adh_coupon_info.coupon_status=2\n" +
            " AND (adh_shop_category.id = #{categoryId}  OR adh_shop_category.parent_id = #{categoryId} ) AND adh_merch_info.merch_city = #{city}  order by adh_coupon_info.sort_num desc ")
    List<Map<String,Object>> queryMerchCoupponByCategoryAndCity(@Param("categoryId") String categoryId,@Param("city") String city);

    @Select(" SELECT  adh_merch_info.* FROM adh_merch_info \n" +
            "  LEFT JOIN adh_shop_category ON adh_shop_category.id = adh_merch_info.merch_category\n" +
            "  WHERE adh_merch_info.merch_status='1' \n" +
            "  AND (adh_shop_category.id = #{categoryId}  OR adh_shop_category.parent_id = #{categoryId} ) AND adh_merch_info.merch_city =  #{city}  ")
    List<Map<String,Object>> queryMerchByCategoryAndCity(@Param("categoryId") String categoryId,@Param("city") String city);

    @Select(" SELECT  adh_coupon_info.* FROM adh_merch_info LEFT JOIN adh_coupon_info  ON adh_merch_info.id = adh_coupon_info.merch_id\n" +
            "             LEFT JOIN adh_shop_category ON adh_shop_category.id = adh_merch_info.merch_category\n" +
            "             WHERE adh_merch_info.merch_status='1' \n" +
            "              AND adh_coupon_info.coupon_status=2\n" +
            "              AND (\n" +
            "              adh_merch_info.merch_category_name LIKE CONCAT('%',#{searchKey},'%') OR\n" +
            "              adh_merch_info.merch_name LIKE CONCAT('%',#{searchKey},'%') OR\n" +
            "              adh_coupon_info.coupon_name LIKE CONCAT('%',#{searchKey},'%') OR\n" +
            "              adh_coupon_info.commodity_title LIKE CONCAT('%',#{searchKey},'%') \n" +
            "              )")
    List<Map<String,Object>> searchCoupon(@Param("searchKey") String searchKey);


}
